package com.exam.online.system.dao;

import com.exam.online.system.entity.Course;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CourseDAO {
    int deleteByPrimaryKey(Integer id);

    int insert(Course record);

    int insertSelective(Course record);

    Course selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Course record);

    int updateByPrimaryKey(Course record);

    @Select("select * from t_course limit #{pageNo},#{pageSize}")
    List<Course> getAllCourse(@Param("pageNo") Integer pageNo, @Param("pageSize") Integer pageSize);

    @Select("select count(*) from t_course ")
    Integer getAllCourseCount();

    /**
     * 通过课程名称和年级查找课程信息
     *
     * @param courseName
     * @param gradeId
     */
    @Select("select * from `t_course` where course_name = #{courseName} and grade = #{gradeId}")
    Course selectByCourseNameAndGradeId(@Param("courseName") String courseName, @Param("gradeId") Integer gradeId);

    @Select("SELECT * FROM `t_course` as c,`t_stu_course_relation` as s where c.id=s.course_id and s.stu_id = #{stuId} and c.grade = #{grade} limit #{pageNo},#{pageSize}")
    List<Course> selectByStuIdAndGradeId(@Param("stuId") Integer stuId, @Param("grade") Integer grade, @Param("pageNo") int pageNo, @Param("pageSize") Integer pageSize);

    @Select("SELECT count(*) FROM `t_course` as c,`t_stu_course_relation` as s where c.id=s.course_id and s.stu_id = #{stuId} and c.grade = #{grade}")
    int totalByStuIdAndGradeId(@Param("stuId") Integer stuId, @Param("grade") Integer grade);

    @Select("select * from `t_course` where course_name = #{courseName}")
    Course selectByCourseName(@Param("courseName") String courseName);

    @Select("select * from `t_course` where grade = #{gradeId}")
    List<Course> selectByGradeId(@Param("gradeId") Integer gradeId);
}